import { Form,FormItem,Input,Button,message } from 'antd';
import styles from './addProduct.css';
import {connect} from "dva";

function AddProduct(props) {
	const FormItem = Form.Item;
	let value1=''
	let value2=''
	let value3=''
	let value4=''
	let value5=''
	let value6=''
  return (
    <div className={styles.normal}>
      <h1>商品添加</h1>
	  <Form className = 'form-container' >
	  
	  <FormItem >
	   <Input defaultValue="富邦美喆家居-" type='text' ref = {(val) => value1 = val}/>
	   < /FormItem >
	   <FormItem >
	  <Input placeholder="请输入商品简介" type='text' ref = {(val) => value2 = val}/>
	  < /FormItem >
	  <FormItem >
	  <Input placeholder="请输入商品库存" type='text' ref = {(val) => value3 = val}/>
	  < /FormItem >
	  <FormItem >
	  <Input placeholder="请输入商品价格" type='text' ref = {(val) => value4 = val}/>
	  < /FormItem >
	  <FormItem >
	  <Input placeholder="请输入图片链接" type='text' ref = {(val) => value5 = val}/>
	  < /FormItem >
	  <FormItem >
	  <Input placeholder="请输入商品分类id" type='text' ref = {(val) => value6 = val}/>
	  < /FormItem >
	  </Form>
	  <div className={styles.btn}>
		<Button type="primary"
		onClick = {
			() => props.dispatch({
				type: 'info/postAddProduct',
				payload: {
					  name:value1.state.value,
					  descriptions:value2.state.value,
					  quantity:value3.state.value,
					  price:value4.state.value,
					  coverImg:value5.state.value,
					  productCategory:value6.state.value
				}
			}).then(()=>{
				console.log(props.mess)
				if(props.mess){
					message.success('添加成功~')
					props.history.push('/home/productList')
				}
			})
		}
		>添加商品</Button>
	  </div>
	  
    </div>
  );
}
export default connect(state => state.info)(AddProduct);